#!/bin/bash
set -e

SCRIPT_BASE_DIR=$( dirname "${BASH_SOURCE[0]}" )
source "${SCRIPT_BASE_DIR}/common/fs_utils.sh"
source "${SCRIPT_BASE_DIR}/common/cs_utils.sh"

function usage () {
	echo "Usage: $( basename "$0" ) [-hi] [<root_dir>]"
    echo "     对<root_dir>内指定文件建立cscope数据库"
    echo "     -i: 列出索引的信息，如文件扩展名，exclude目录"
    echo "     -h: 输出此信息"
    echo "     root_dir: 源代码根目录,缺省为当前目录"
	exit 1
}

exts=(bb bbappend inc conf bbclass)
fnames=()
excludeNames=()

while getopts ":ih" arg
do
    case ${arg} in
        i)
            cs_info exts fnames excludeNames
            exit 0
            ;;
        *)
            usage
            ;;
    esac
done

root="."
if [ -n "$1" ]
then
    root="$1"
fi

# 传递数组变量名字
build_cs_file_list "${root}" exts fnames excludeNames

{
    echo "Build cscope DB in ${root} ..."
    cd ${root}
    cscope -Rbqk
}

echo "Done."

